package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketOrder;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.service.MarketWXUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MarketWXUserServiceImpl implements MarketWXUserService {
    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Override
    public Map<String, Object> getUserIndex() {
        HashMap<String, Object> order = new HashMap<>();
        order.put("unpaid",getMarketOrderStatusCount((short)101));
        order.put("unship",getMarketOrderStatusCount((short)201));
        order.put("unrecv",getMarketOrderStatusCount((short)301));
        order.put("uncomment",getMarketOrderStatusCount((short)401));
        return order;
    }

    private Integer getMarketOrderStatusCount(short s) {
        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria or = marketOrderExample.or();
        or.andDeletedEqualTo(false);
        or.andOrderStatusEqualTo(s);
        List<MarketOrder> marketOrders = marketOrderMapper.selectByExample(marketOrderExample);
        return marketOrders.size();
    }
}
